package com.googlecode.sc2dm.receiver;

import android.content.Context;
import android.content.Intent;
import com.googlecode.sc2dm.annotations.AnnotationFinder;
import com.googlecode.sc2dm.annotations.types.OnErrorObject;
import com.googlecode.sc2dm.annotations.types.OnMessageObject;

import java.util.List;

/**
 * @Author Jarle Hansen (jarle@jarlehansen.net)
 * Created: 6:35 PM - 9/18/11
 */
public class MessageReceiver {
    private OnMessageObject onMessage = null;
    private OnErrorObject onError = null;

    public MessageReceiver() {
    }

    public void findAnnotations(List<Class<?>> classes) {
        for (Class clazz : classes) {
            onMessage = AnnotationFinder.findOnMessage(clazz);
            onError = AnnotationFinder.findOnError(clazz);
        }
    }

    public void onMessage(Context context, Intent intent) {
        if (onMessage != null)
            onMessage.invokeOnMessage(context, intent);
    }

    public void onError(Context context, String errorMsg) {
        if (onError != null)
            onError.invokeOnError(context, errorMsg);
    }
}
